home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / status / omnimoni.0 / omnimoni / OmniMoni / Demonstration < prev    next >
Encoding:
Tcl/Tk script  |  1995-11-12  |  2.3 KB  |  75 lines

  1. #!/usr/local/bin/wish -f
  2.  
  3. text .text -relief raised -bd 2 -yscrollcommand ".scroll set"
  4. scrollbar .scroll -command ".text yview"
  5. pack .scroll -side right -fill y
  6. pack .text -side left -fill both -expand yes
  7. .text config -setgrid 1 -wrap word
  8. if {[catch {.text config -font "*-new century schoolbook-medium-r-normal--14-*"}]} {
  9.     puts "You don't have the font New Century Schoolbook at 14 points."
  10. }
  11.  
  12. proc loadFile { file } {
  13.     .text delete 1.0 end
  14.     set f [open $file]
  15.     while {![eof $f]} {
  16.     .text insert end [read $f 1024]
  17.     }
  18.     close $f
  19. }
  20.  
  21. proc forAllMatches { w pattern script } {
  22.     scan [$w index end] %d numLines
  23.     for {set i 1} {$i < $numLines} {incr i} {
  24.     $w mark set last $i.0
  25.     while {[regexp -indices $pattern \
  26.            [$w get last "last lineend"] indices]} {
  27.        $w mark set first "last + [lindex $indices 0] chars"
  28.        $w mark set last "last + 1 chars + [lindex $indices 1] chars"
  29.        uplevel $script
  30.         }
  31.     }
  32. }
  33.  
  34. bind all <Q> "exit"
  35. bind all <Down> ".text yview scroll 1 unit"
  36. bind all <Up> ".text yview scroll -1 unit"
  37. bind all <Next> ".text yview scroll 1 page"
  38. bind all <Prior> ".text yview scroll -1 page"
  39.  
  40. loadFile "demos/demonstration.txt"
  41.  
  42. forAllMatches .text "<DEMO-IT>.*</DEMO-IT>" {
  43.     .text delete first "first + 9 chars"
  44.     .text delete "last - 10 chars" last
  45.     set demo_name [.text get first last]
  46.     .text tag add $demo_name first last
  47.     .text tag bind $demo_name <Button-1> "exec wish -f src/omnimoni.tcl -f $demo_name &"
  48.     .text tag bind $demo_name <Button-2> "exec wish -f src/omnimoni.tcl -v 4 -f $demo_name &"
  49.     .text tag add demo-it first last
  50. }
  51.  
  52. forAllMatches .text "<SECTION>.*</SECTION>" {
  53.     .text delete first "first + 9 chars"
  54.     .text delete "last - 10 chars" last
  55.     set demo_name [.text get first last]
  56.     .text tag add section first last
  57. }
  58.  
  59. forAllMatches .text "<FX>.*" {
  60.     .text delete first "first + 4 chars"
  61.     .text tag add fixed first last
  62. }
  63.  
  64. .text tag config demo-it -fore "red"
  65.  
  66. if {[catch {.text tag config fixed -font "*-courier-medium-r-normal--14-*"}]} {
  67.     puts "You dont have the font Courier at 14 points."
  68. }
  69.  
  70. if {[catch {.text tag config section -font "*-new century schoolbook-bold-r-normal--18-*"}]} {
  71.     puts "You don't have the font New Century Schoolbook bold at 18 points."
  72. }
  73.  
  74. .text config -state disabled
  75.